/** 
* All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
* 
* PmInvoiceRecordService
* 项目开票记录
* 
* 修改纪录
* 2020-09-24 版本：1.0 shenyouyi 创建。
* @version 版本：1.0
* @author 作者：shenyouyi
* 创建日期：2020-09-24
*/
package com.topscomm.pm.service.impl;

import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.pm.service.IPmInvoiceRecordService;
import com.topscomm.pm.service.impl.auto.PmInvoiceRecordServiceAuto;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service(value = "pmInvoiceRecordService")
@Scope(value = "singleton")
public class PmInvoiceRecordService extends PmInvoiceRecordServiceAuto implements IPmInvoiceRecordService {

    /**
     * @author: shenyouyi
     * @date: 2020-09-26
     * @param: invoiceapplyid
     * @param: invoicecodes
     * @param: cancelStatus
     * @return
     * @description: 更新发票状态
     * @modify:
     */
    @Transactional
    public void setInvoiceState(Long invoiceapplyid, String invoicecodes, String cancelStatus) {
        if (!StringUtil.isEmpty(invoicecodes)) {
            String[] billNoArray = invoicecodes.split(",");
            StringBufferProxy invoicecodePara = new StringBufferProxy();
            for (String oldinvoicecodeStr : billNoArray) {
                invoicecodePara.appendSingle("'{0}',", oldinvoicecodeStr);
            }
            invoicecodePara = invoicecodePara.length() > 0 ? invoicecodePara.substring(0, invoicecodePara.length() - 1) : invoicecodePara;
            Map<String, Object> updateFieldMap = new HashMap<>();
            updateFieldMap.put("iscancel", cancelStatus);
            StringBufferProxy sql = new StringBufferProxy();
            sql.appendSingle("invoiceapplyid = {0} and invoiceno in ({1})", invoiceapplyid, invoicecodePara.toString());
            this.updateByWhere(updateFieldMap, sql.toString());
        }
    }

}
